/**************************************************************************
	Replication do-file: "Corruption in Customs"
	Cyril Chalendard, Ana Fernandes, Gael Raballand and Bob Rijkers
	
	Created on: 01/07/2022
**************************************************************************/

clear all
set more off, perm
cap log close
cls

* Extra commands: remove the asterisk to install
*net install cleanplots, from("https://tdmize.github.io/data/cleanplots")
*set scheme cleanplots, perm

* ----------------------- DIRECTORIES AND FOLDERS ----------------------- *

* Directories in which data are stored
global main "PUT YOUR DIRECTORY PATH HERE"
cd "$folder"

* Folders
global outputdata = "$main\Output Data"
cap mkdir "$main\Figures"
global figures = "$main\Figures"

* ----------------------------- BEGINS HERE ----------------------------- *

* -------
* Dataset
* -------
use "$outputdata\CFRR.dta", clear // open dataset

* New variables
gen predicted = (ms_b-eis_f)

* Rename variables
rename (ms_b ia_ms_b) (observed initial)


* --------
* Figure 3
* --------

* Panel A: all declarations
* -------------------------
twoway (kdensity predicted if sample_reg==1 & observed<0.30 & observed>=0 & predicted<0.30 & predicted>=0 & initial>=0 & initial<0.3, lcolor(gs4) lpattern(solid) lwidth(medthick)) ///
		(kdensity initial if sample_reg==1 & observed<0.30 & observed>=0 & predicted<=0.30 & predicted>=0 & initial>=0 & initial<0.3, lcolor(gs7) lpattern(longdash) lwidth(medthick)) ///
		(kdensity observed if sample_reg==1 & observed<0.30 & observed>=0 & predicted<=0.30 & predicted>=0 & initial>=0 & initial<0.3, lcolor(gs10) lpattern(dash) lwidth(medthick)), ///
		xlabel(, nogrid) ///
		ylabel(, angle(0) labsize(small) nogrid) ///
		ytitle("Frequency", size(small) color(black)) ///
		xtitle("Inspector share of a given broker's declarations", size(small) color(black)) ///
		legend(pos(6) ring(10) col(3) order(1 "Predicted assignment" 2 "Initial assignment" 3 "Final assignment") size(small)) ///
		name(Figure_3a, replace)
graph export "$figures\Figure_3a.eps", as(tif) replace
graph export "$figures\Figure_3a.pdf", as(pdf) replace

* Panel B: reassigned declarations
* --------------------------------
twoway (kdensity predicted if sample_reg==1 & observed<0.30 & observed>=0 & predicted<0.30 & predicted>=0 & initial>=0 & initial<0.3 & reass==1, lcolor(gs4) lpattern(solid) lwidth(medthick)) ///
		(kdensity initial if sample_reg==1 & observed<0.30 & observed>=0 & predicted<=0.30 & predicted>=0 & initial>=0 & initial<0.3 & reass==1, lcolor(gs7) lpattern(longdash) lwidth(medthick)) ///
		(kdensity observed if sample_reg==1 & observed<0.30 & observed>=0 & predicted<=0.30 & predicted>=0 & initial>=0 & initial<0.3 & reass==1, lcolor(gs10) lpattern(dash) lwidth(medthick)), ///
		xlabel(, nogrid) ///
		ylabel(, angle(0) labsize(small) nogrid) ///
		ytitle("Frequency", size(small) color(black)) ///
		xtitle("Inspector share of a given broker's declarations", size(small) color(black)) ///
		legend(pos(6) ring(10) col(3) order(1 "Predicted assignment" 2 "Initial assignment" 3 "Final assignment") size(small)) ///
		name(Figure_3b, replace)
graph export "$figures\Figure_3b.eps", as(eps) replace
graph export "$figures\Figure_3b.pdf", as(pdf) replace


* -------------------------------- ENDS HERE -------------------------------- *